/**
 * @author Allen
 * @since 2011-09-10
 * 百科接口实现类
 */
package com.qeado.baike.dao.ibatis;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.qeado.baike.dao.BaikeDao;
import com.qeado.baike.model.Baike;
import com.qeado.baike.model.BaikeRef;
import com.qeado.base.BaseDao;
import com.qeado.util.PageHelper;
import com.qeado.util.ParameterMap;

@Repository
@SuppressWarnings("unchecked")
public class BaikeDaoImplement extends BaseDao implements BaikeDao {

	public String insertBaike(Baike baike) {
		// TODO Auto-generated method stub
		return null;
	}

	public PageHelper listAll(int pageNum, int pageSize, String typeCode,
			String orderBy, String asc) {
		// TODO Auto-generated method stub
		return null;
	}

	public PageHelper listByKey(int pageNum, int pageSize, String typeCode,
			String orderBy, String asc, String key) {
		// TODO Auto-generated method stub
		return null;
	}

	public Baike queryById(String id) {
		return (Baike)this.getSqlMapClientTemplate().queryForObject("Baike.queryById",id);
	}

	public String insertBaike(BaikeRef baikeRef) {
		// TODO Auto-generated method stub
		return null;
	}

	public Baike queryByWord(String baikeWord) {
		return (Baike)this.getSqlMapClientTemplate().queryForObject("Baike.queryByWord",baikeWord);
	}

	public boolean createBaike(Baike baike) {
		try {
			this.getSqlMapClientTemplate().insert("Baike.createBaike", baike);
			return true;
		} catch (Exception e) {
			logger.error("Database Insert Error!");
			return false;
		}
	}

	public PageHelper listByKey(int pageNum, int pageSize, String key,
			String orderBy, String asc) throws Exception{
		PageHelper pageHelper = new PageHelper();
		pageHelper.setPageSize(pageSize);
		int startRecored = (pageNum - 1) * pageSize;
		ParameterMap parameterMaps = new ParameterMap();
		parameterMaps.setPageSize(pageSize);
		parameterMaps.setStartRecored(startRecored);
		parameterMaps.setParameter1(key);
		parameterMaps.setParameter2(orderBy);
		parameterMaps.setParameter3(asc);
		pageHelper.setObjList((List) this.getSqlMapClientTemplate()
				.queryForList("Baike.listByKey", parameterMaps));
		pageHelper.setRecordCount((Integer) this.getSqlMapClientTemplate()
				.queryForObject("Baike.getCountByKey", key));
		pageHelper.setCurrentPage(pageNum);
		pageHelper.setPageCount();
		return pageHelper;	
	}

	public PageHelper listBySort(int pageNum, int pageSize, String typeCode,
			String orderBy, String asc)  throws Exception{
		PageHelper pageHelper = new PageHelper();
		pageHelper.setPageSize(pageSize);
		int startRecored = (pageNum - 1) * pageSize;
		ParameterMap parameterMaps = new ParameterMap();
		parameterMaps.setPageSize(pageSize);
		parameterMaps.setStartRecored(startRecored);
		parameterMaps.setParameter1(typeCode);
		parameterMaps.setParameter2(orderBy);
		parameterMaps.setParameter3(asc);
		pageHelper.setObjList((List) this.getSqlMapClientTemplate()
				.queryForList("Baike.listBySort", parameterMaps));
		pageHelper.setRecordCount((Integer) this.getSqlMapClientTemplate()
				.queryForObject("Baike.getCountBySort", typeCode));
		pageHelper.setCurrentPage(pageNum);
		pageHelper.setPageCount();
		return pageHelper;	
	}

	public PageHelper listAll(int pageNum, int pageSize, String orderBy,
			String asc) throws Exception {
		PageHelper pageHelper = new PageHelper();
		pageHelper.setPageSize(pageSize);
		int startRecored = (pageNum - 1) * pageSize;
		ParameterMap parameterMaps = new ParameterMap();
		parameterMaps.setPageSize(pageSize);
		parameterMaps.setStartRecored(startRecored);
		parameterMaps.setParameter2(orderBy);
		parameterMaps.setParameter3(asc);
		pageHelper.setObjList((List) this.getSqlMapClientTemplate()
				.queryForList("Baike.listAll", parameterMaps));
		pageHelper.setRecordCount((Integer) this.getSqlMapClientTemplate()
				.queryForObject("Baike.getCount") );
		pageHelper.setCurrentPage(pageNum);
		pageHelper.setPageCount();
		return pageHelper;	
	}

}
